package com.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class HelloController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @RequestMapping("/")
    public String index() {
        return "Hello Spring Boot 2.0!";
    }

    @RequestMapping("/test")
    public Object test() {
        Query query = new Query();
        query.skip(1);
        query.limit(1);
        query.with(Sort.by(
                Sort.Order.asc("_id")));
        List<Map> list = mongoTemplate.find(query, Map.class, "cde_item_v3");
        System.out.println(list);

        return "ok";
    }
}